def func(name,sex='男'):
    print(name)
    print(sex)
func('alex')

def func(name,alist=[]):
    alist.append(name)
    print(alist)
    return alist
ret=func('alex')
print(ret,id(ret))
ret2=func('太白金星')
print(ret2,id(ret2))


def func(a,list=[]):
    list.append(a)
    return list
print(func(10,))#[10]
print(func(20,[]))#[20]
print(func(100,))#[10, 100]



def func(a,list=[]):
    list.append(a)
    return list
ret=func(10,)#[10]
ret1=func(20,[])#[20]
ret3=func(100,)#[10,100]
print(ret)#[10,100]
print(ret1)#[20]
print(ret3)#[10,100]
'''
[10, 100]
[20]
[10, 100]
'''
'''
count=1
def func():
    count+=1
    print(count)
func()#UnboundLocalError: local variable 'count' referenced before assignment
'''
'''
def func():
    print(count)
    count+=1  尝试修改全局变量，报错
func()#UnboundLocalError: local variable 'count' referenced before assignment
'''
count=1
def func():
    print(count)
func()

# count=1
# def func():
#     print(count)#局部有count，就会引用局部的count，所以报错
#     count+=1  #尝试修改全局变量，报错
# func()#UnboundLocalError: local variable 'count' referenced before assignment

count=1

#在函数中，如果你定义了一个变量，但是定义这个变量之前对其引用率，那么解释器就认为：语法问题
#应该在使用之前先定义
def func():
    print(count)#局部有count，就会引用局部的count，所以报错
    count=3  #尝试修改全局变量，报错
func()#UnboundLocalError: local variable 'count' referenced before assignment








